package com.weipai.tbswebviewtest;

import android.Manifest;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;


import butterknife.ButterKnife;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.OnShowRationale;
import permissions.dispatcher.PermissionRequest;
import permissions.dispatcher.RuntimePermissions;

@RuntimePermissions
public class MainActivity extends AppCompatActivity {
//public class MainActivity extends XWalkActivity {

//    @BindView(R.id.xwalkview)
//    XWalkView xwalkview;
//
//    @Override
//    protected void onXWalkReady() {
//        XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, true);   //开启默认动画
//        XWalkSettings setting = xwalkview.getSettings();
//        setting.setLoadWithOverviewMode(false);
//        setting.setUserAgentString("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36");
//        //支持js
//        setting.setJavaScriptEnabled(true);
//        //支持通过JS打开新窗口
//        setting.setJavaScriptCanOpenWindowsAutomatically(true);
//        //将图片调整到合适webview的大小
//        setting.setUseWideViewPort(true);
//        //缩放至屏幕的大小
//        setting.setLoadWithOverviewMode(true);
//        //支持自动加载图片
//        setting.setLoadsImagesAutomatically(true);
//        //支持多窗口
//         setting.supportMultipleWindows();
//        setting.setBuiltInZoomControls(true);
//         setting.setSupportZoom(true);
//        setting.setAllowFileAccess(true);
//        setting.setDomStorageEnabled(false);
//        setting.setAllowContentAccess(false);
//        //支持获取手势焦点
//        xwalkview.requestFocusFromTouch();
//        xwalkview.requestFocus();
//        setting.setCacheMode(XWalkSettings.LOAD_NO_CACHE);
//        xwalkview.setResourceClient(new XWalkResourceClient(xwalkview){
//            @Override
//            public void onLoadStarted(XWalkView view, String url) {
//                super.onLoadStarted(view, url);
//            }
//
//            @Override
//            public void onLoadFinished(XWalkView view, String url) {
//                super.onLoadFinished(view, url);
//            }
//
//            @Override
//            public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
//               view.loadUrl(url);
//                return true;
//            }
//
//            @Override
//            public void onReceivedSslError(XWalkView view, ValueCallback<Boolean> callback, SslError error) {
//                callback.onReceiveValue(true);
//                super.onReceivedSslError(view, callback, error);
//            }
//
//            @Override
//            public void onReceivedLoadError(XWalkView view, int errorCode, String description,
//                                            String failingUrl) {
//                super.onReceivedLoadError(view, errorCode, description, failingUrl);
//            }
//        });
//
//        xwalkview.setUIClient(new XWalkUIClient(xwalkview){
//
//        });
//        xwalkview.loadUrl("http://192.168.1.37:8089/main");
//    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        MainActivityPermissionsDispatcher.callWithPermissionCheck(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, false);
    }

    @NeedsPermission({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission
            .WRITE_EXTERNAL_STORAGE})
    void call() {
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        MainActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode,
                grantResults);
    }

    @OnShowRationale({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission
            .WRITE_EXTERNAL_STORAGE})
    void call2(final PermissionRequest request) {
    }
}
